package com.bear;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiuShanshan
 * @version V1.0
 * @Description
 */
@SpringBootApplication
@RestController
public class Service2Application {

    // 注入配置文件上下文, 可动态获取nacos中配置数据
    @Autowired
    private ConfigurableApplicationContext applicationContext;


    public static void main(String[] args) {
        SpringApplication.run(Service2Application.class, args);
    }

    @RequestMapping("/getConfigs")
    public void getConfigs(){
        // service2-3
        String property3 = applicationContext.getEnvironment().getProperty("service22.uat");
        System.out.println(property3);
        // service2-4
        System.out.println("============================================");
        String property4 = applicationContext.getEnvironment().getProperty("service.demo4");
        System.out.println(property4);
    }

    @RequestMapping("/getConfig2")
    public void getConfig2(){
        String property1 = applicationContext.getEnvironment().getProperty("common.name");
        String property = applicationContext.getEnvironment().getProperty("class.name");
        System.out.println(property);
        System.out.println(property1);
    }

    @RequestMapping("/getConfig3")
    public void getConfig3(){
        String property1 = applicationContext.getEnvironment().getProperty("common.name");
        System.out.println(property1);
    }
}
